using SS;
using System;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Windows.Forms;
using TVSBH.func;
namespace TVSGPP.doctor
{
	public class frmPrintUsage : Form
	{
		private IContainer components = null;
		private Label label1;
		private Label label2;
		public Label lblBillID;
		private Button btnPrint;
		private Button btnClose;
		private DataGridView dgvRep;
		private DataGridViewTextBoxColumn P_Name;
		private DataGridViewTextBoxColumn Usage;
		private DataTable objTable = new DataTable();
		protected override void Dispose(bool disposing)
		{
			if (disposing && this.components != null)
			{
				this.components.Dispose();
			}
			base.Dispose(disposing);
		}
		private void InitializeComponent()
		{
			DataGridViewCellStyle dataGridViewCellStyle = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle2 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle3 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle4 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle5 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle6 = new DataGridViewCellStyle();
			this.label1 = new Label();
			this.lblBillID = new Label();
			this.label2 = new Label();
			this.btnPrint = new Button();
			this.btnClose = new Button();
			this.dgvRep = new DataGridView();
			this.P_Name = new DataGridViewTextBoxColumn();
			this.Usage = new DataGridViewTextBoxColumn();
			((ISupportInitialize)this.dgvRep).BeginInit();
			base.SuspendLayout();
			this.label1.BackColor = Color.FromArgb(255, 255, 128);
			this.label1.BorderStyle = BorderStyle.Fixed3D;
			this.label1.Location = new Point(7, 6);
			this.label1.Name = "label1";
			this.label1.Size = new Size(79, 22);
			this.label1.TabIndex = 0;
			this.label1.Text = "Đơn thuốc :";
			this.label1.TextAlign = ContentAlignment.MiddleRight;
			this.lblBillID.BackColor = Color.FromArgb(255, 255, 128);
			this.lblBillID.BorderStyle = BorderStyle.Fixed3D;
			this.lblBillID.Location = new Point(89, 6);
			this.lblBillID.Name = "lblBillID";
			this.lblBillID.Size = new Size(140, 22);
			this.lblBillID.TabIndex = 1;
			this.lblBillID.Text = "-:-";
			this.lblBillID.TextAlign = ContentAlignment.MiddleCenter;
			this.label2.BackColor = Color.White;
			this.label2.BorderStyle = BorderStyle.Fixed3D;
			this.label2.Location = new Point(232, 6);
			this.label2.Name = "label2";
			this.label2.Size = new Size(395, 22);
			this.label2.TabIndex = 2;
			this.label2.Text = "Dưới đây là hướng dẫn sử dụng đề nghị - Hãy sửa nó nếu cần";
			this.label2.TextAlign = ContentAlignment.MiddleCenter;
			this.btnPrint.Cursor = Cursors.Hand;
			this.btnPrint.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnPrint.Location = new Point(219, 483);
			this.btnPrint.Name = "btnPrint";
			this.btnPrint.Size = new Size(97, 30);
			this.btnPrint.TabIndex = 1;
			this.btnPrint.Text = "In hướng dẫn";
			this.btnPrint.UseVisualStyleBackColor = true;
			this.btnPrint.Click += new EventHandler(this.btnPrint_Click);
			this.btnClose.Cursor = Cursors.Hand;
			this.btnClose.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnClose.Location = new Point(319, 483);
			this.btnClose.Name = "btnClose";
			this.btnClose.Size = new Size(104, 30);
			this.btnClose.TabIndex = 2;
			this.btnClose.Text = "Thoát [ ESC ]";
			this.btnClose.UseVisualStyleBackColor = true;
			this.btnClose.Click += new EventHandler(this.btnClose_Click);
			this.dgvRep.AllowUserToAddRows = false;
			this.dgvRep.AllowUserToDeleteRows = false;
			this.dgvRep.AllowUserToResizeColumns = false;
			this.dgvRep.AllowUserToResizeRows = false;
			dataGridViewCellStyle.BackColor = Color.FromArgb(192, 255, 255);
			dataGridViewCellStyle.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.dgvRep.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle;
			this.dgvRep.Anchor = (AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right);
			this.dgvRep.BackgroundColor = Color.White;
			this.dgvRep.BorderStyle = BorderStyle.Fixed3D;
			this.dgvRep.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single;
			dataGridViewCellStyle2.BackColor = SystemColors.Control;
			dataGridViewCellStyle2.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			dataGridViewCellStyle2.ForeColor = SystemColors.WindowText;
			dataGridViewCellStyle2.SelectionBackColor = Color.Aqua;
			dataGridViewCellStyle2.SelectionForeColor = Color.Black;
			this.dgvRep.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle2;
			this.dgvRep.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
			this.dgvRep.Columns.AddRange(new DataGridViewColumn[]
			{
				this.P_Name,
				this.Usage
			});
			this.dgvRep.Cursor = Cursors.Hand;
			this.dgvRep.EnableHeadersVisualStyles = false;
			this.dgvRep.Location = new Point(7, 31);
			this.dgvRep.MultiSelect = false;
			this.dgvRep.Name = "dgvRep";
			dataGridViewCellStyle3.BackColor = SystemColors.Control;
			dataGridViewCellStyle3.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			dataGridViewCellStyle3.ForeColor = Color.Black;
			dataGridViewCellStyle3.SelectionBackColor = Color.Aqua;
			dataGridViewCellStyle3.SelectionForeColor = Color.Black;
			this.dgvRep.RowHeadersDefaultCellStyle = dataGridViewCellStyle3;
			this.dgvRep.RowHeadersVisible = false;
			this.dgvRep.RowHeadersWidth = 26;
			this.dgvRep.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;
			dataGridViewCellStyle4.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.dgvRep.RowsDefaultCellStyle = dataGridViewCellStyle4;
			this.dgvRep.RowTemplate.DefaultCellStyle.BackColor = Color.White;
			this.dgvRep.RowTemplate.DefaultCellStyle.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.dgvRep.RowTemplate.DefaultCellStyle.ForeColor = Color.Black;
			this.dgvRep.RowTemplate.DefaultCellStyle.SelectionBackColor = Color.Aqua;
			this.dgvRep.RowTemplate.DefaultCellStyle.SelectionForeColor = Color.Black;
			this.dgvRep.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
			this.dgvRep.Size = new Size(620, 446);
			this.dgvRep.TabIndex = 5;
			this.P_Name.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.P_Name.DataPropertyName = "P_Name";
			dataGridViewCellStyle5.Alignment = DataGridViewContentAlignment.MiddleLeft;
			dataGridViewCellStyle5.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			dataGridViewCellStyle5.NullValue = null;
			this.P_Name.DefaultCellStyle = dataGridViewCellStyle5;
			this.P_Name.DividerWidth = 1;
			this.P_Name.HeaderText = "Tên thuốc";
			this.P_Name.MinimumWidth = 223;
			this.P_Name.Name = "P_Name";
			this.P_Name.Width = 223;
			this.Usage.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
			this.Usage.DataPropertyName = "Usage";
			dataGridViewCellStyle6.Alignment = DataGridViewContentAlignment.MiddleLeft;
			dataGridViewCellStyle6.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 0);
			dataGridViewCellStyle6.ForeColor = Color.Red;
			this.Usage.DefaultCellStyle = dataGridViewCellStyle6;
			this.Usage.HeaderText = "Liều dùng";
			this.Usage.MinimumWidth = 90;
			this.Usage.Name = "Usage";
			base.AutoScaleDimensions = new SizeF(7f, 15f);
			//base.AutoScaleMode = AutoScaleMode.Font;
			base.ClientSize = new Size(634, 516);
			base.Controls.Add(this.dgvRep);
			base.Controls.Add(this.btnClose);
			base.Controls.Add(this.btnPrint);
			base.Controls.Add(this.label2);
			base.Controls.Add(this.lblBillID);
			base.Controls.Add(this.label1);
			this.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			//base.Icon = (Icon)componentResourceManager.GetObject("$this.Icon");
			base.KeyPreview = true;
			this.MaximumSize = new Size(650, 550);
			this.MinimumSize = new Size(650, 550);
			base.Name = "frmPrintUsage";
			base.ShowInTaskbar = false;
			base.StartPosition = FormStartPosition.CenterScreen;
			this.Text = "..: HƯỚNG DẪN SỬ DỤNG THUỐC THEO ĐƠN THUỐC";
			base.Load += new EventHandler(this.frmPrintUsage_Load);
			base.Shown += new EventHandler(this.frmPrintUsage_Shown);
			base.KeyDown += new KeyEventHandler(this.frmPrintUsage_KeyDown);
			((ISupportInitialize)this.dgvRep).EndInit();
			base.ResumeLayout(false);
		}
		public frmPrintUsage()
		{
			this.InitializeComponent();
		}
		private void getUsage()
		{
			try
			{
				this.dgvRep.AutoGenerateColumns = false;
				SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
				string cmdText = "SELECT PID,P_Name,Usage FROM [TabProducts] WHERE [Pid] IN (SELECT Pid FROM [TabDetailBill] WHERE [billID] = '" + this.lblBillID.Text.Trim() + "')";
				SqlCommand selectCommand = new SqlCommand(cmdText, sqlConnection);
				SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(selectCommand);
				DataSet dataSet = new DataSet();
				sqlConnection.Open();
				sqlDataAdapter.Fill(dataSet);
				this.dgvRep.DataSource = dataSet.Tables[0];
				sqlConnection.Close();
				sqlConnection.Dispose();
				sqlDataAdapter.Dispose();
				dataSet.Dispose();
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
		}
		private void frmPrintUsage_Load(object sender, EventArgs e)
		{
		}
		private void btnClose_Click(object sender, EventArgs e)
		{
			base.Close();
		}
		private void frmPrintUsage_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyData == Keys.Escape)
			{
				base.Close();
			}
		}
		private void frmPrintUsage_Shown(object sender, EventArgs e)
		{
			if (this.lblBillID.Text.Trim() != "")
			{
				this.getUsage();
			}
		}
		private void btnPrint_Click(object sender, EventArgs e)
		{
			this.objTable = new DataTable();
			DataColumn column = new DataColumn("C1", typeof(string));
			DataColumn column2 = new DataColumn("C2", typeof(string));
			this.objTable.Columns.Add(column);
			this.objTable.Columns.Add(column2);
			for (int i = 0; i < this.dgvRep.RowCount; i++)
			{
				this.objTable.Rows.Add(new object[]
				{
					this.dgvRep.Rows[i].Cells[0].Value.ToString().ToUpper(),
					this.dgvRep.Rows[i].Cells[1].Value.ToString()
				});
			}
			frmUsage frmUsage = new frmUsage();
			frmUsage.objTable = this.objTable;
			frmUsage.billID = this.lblBillID.Text;
			frmUsage.Run();
			frmUsage.Document.Print(true, false, false);
		}
	}
}
